package util

import (
	"crypto/md5"
	"encoding/hex"
	"fmt"
	"math/rand"
	"strings"
	"time"
)
//MD5 通用md5加密函数
func MD5(str string) string {
	md5Str := md5.New()
	md5Str.Write([]byte(str))
	result := hex.EncodeToString(md5Str.Sum(nil))
	return result
}
//GenValidateCode 产生随机数
func GenValidateCode(width int) string {
	str := "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
	numeric := []byte(str)

	r := len(numeric)

	rand.Seed(time.Now().UnixNano())

	var sb strings.Builder
	for i := 0; i < width; i++ {

		fmt.Fprintf(&sb, "%v", string(numeric[rand.Intn(r)]))
	}
	return sb.String()

}
